Elementary Work Vectors 您所在的位置:网站首页 iwork and work Elementary Work Vectors

Elementary Work Vectors

2023-12-16 05:19| 来源: 网络整理| 查看: 265

In mdlInitializeSizes, specify the size of the work vectors using the ssSetNumXWork macro, for example:

ssSetNumPWork(S, 2);

This macro indicates how many elements the work vector contains, however, the Simulink engine does not allocate memory, at this time.

An S-function can defer specifying the length of the work vectors until all information about the S-function inputs is available by passing the value DYNAMICALLY_SIZED to the ssSetNumXWork macro. If an S-function defers specifying the length of the work vectors in mdlInitializeSizes, it must provide a mdlSetWorkWidths method to set up the work vectors.

Note

If an S-function uses mdlSetWorkWidths, all work vectors used in the S-function must be set to DYNAMICALLY_SIZED in mdlInitializeSizes, even if the exact value is known before mdlInitializeSizes is called. The sizes to be used by the S-function are than specified in mdlSetWorkWidths.

For an example, see sfun_dynsize.c.

In mdlStart, assign values to the work vectors that are initialized only at the start of the simulation. Use the ssGetXWork macro to retrieve a pointer to each work vector and use the pointer to initialize the work vector values. Alternatively, use the ssGetXWorkValues to assign values to particular elements of the work vector.

The Simulink engine calls the mdlStart method once at the beginning of the simulation. Before calling this method, the engine allocates memory for the work vectors. Do not use the mdlStart method for data that needs to be reinitialized over the course of the simulation, for example, data that needs to be reinitialized when an enabled subsystem containing the S-function is enabled.

In mdlInitializeConditions, initialize the values of any work vectors that might need to be reinitialized at certain points in the simulation. The engine executes mdlInitializeConditions at the beginning of the simulation and any time an enabled subsystem containing the S-function is reenabled.

In mdlOutputs, mdlUpdate, etc., use the ssGetXWork macro to retrieve a pointer to the work vector and use the pointer to access or update the work vector values.

Write an mdlRTW method to allow the Target Language Compiler (TLC) to access the work vector. This step is not necessary if the S-function uses DWork vectors. For information on writing parameter data in an mdlRTW method, see ssWriteRTWParamSettings. For more information on generating code using an mdlRTW method, see Write Fully Inlined S-Functions with mdlRTW Routine (Simulink Coder).



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有